/**
 * @description 生成统计列表
 */
const Mock = require("mockjs");
const Random = Mock.Random;
const getComponentList = require("./getComponentList");

module.exports = function getStatList(len = 10) {
  const componentList = getComponentList();

  const res = [];
  for (let i = 0; i <= len; i++) {
    const stat = {
      _id: Random.id(),
    };
    //增加个个组件的id， value
    componentList.forEach((component) => {
      const { fe_id, type, props } = component;

      switch (type) {
        case "questionInput":
          stat[fe_id] = Random.ctitle(2, 3);
          break;
        case "questionTextarea":
          stat[fe_id] = Random.ctitle();
          break;
        case "questionRadio":
          stat[fe_id] = Random.pick(props.options).text;
          break;
        case "questionCheckbox":
          let cur = Random.integer(1, props.list.length);
          const randomOptions = Random.shuffle(props.list).slice(0, cur);
          stat[fe_id] = randomOptions.map((option) => option.text).join(",");
          break;
        case "questionSlider":
          stat[fe_id] = Random.integer(0, 100);
          break;
      }
    });
    res.push(stat);
  }
  return res;
};
